// vuex的权限模块
import { asyncRoutes, constantRoutes } from '@/router'
// vuex中的permission模块用来存放当前的 静态路由 + 当前用户的 权限路由
const state = {
  routes: []
}
const mutations = {
  // newRoutes可以认为是 用户登录 通过权限所得到的动态路由的部分
  setRoutes(state, routes) {
    state.routes = [...constantRoutes, ...routes]
  }
}

// actions 调用 mutations 存到 state

const actions = {
  filterRoutes(store, menus) {
    // 1.动态路由列表
    // 2.个人权限列表
    const routes = asyncRoutes.filter(route => menus.includes(route.name))
    store.commit('setRoutes', routes)
    return routes
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
